package com.yanqu.road.server.cmd.activity.douluodalu;

import com.yanqu.road.entity.activity.douluodalu.config.DouLuoDaLuConfig;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eLogMoneyType;
import com.yanqu.road.pb.activity.douluodalu.DouLuoDaLuProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.douluodalu.DouLuoDaLuModule;
import com.yanqu.road.server.gameplayer.module.player.CurrencyModule;
import com.yanqu.road.server.manger.activity.douluodalu.DouLuoDaLuMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DOU_LUO_DA_LU_PATRONS_BATTLE_FROM_CROSS,desc = "攻击")
public class DouLuoDaLuPatronsBattleCmdFromCross extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        DouLuoDaLuProto.DouLuoDaLuPatronsBattleRespMsg reqMsg = DouLuoDaLuProto.DouLuoDaLuPatronsBattleRespMsg.parseFrom(packet.getBytes());

        DouLuoDaLuConfig config = DouLuoDaLuMgr.getConfig();

        //结算，有道具奖励
        if(reqMsg.hasSettle()){
            player.getModule(CurrencyModule.class).addCurrency(reqMsg.getSettle().getRewards(), eLogMoneyType.DouLuoDaLuActivity, eLogMoneyType.DouLuoDaLuBattleSettleReward);

            if(reqMsg.hasLog()) {
                DouLuoDaLuProto.DouLuoDaLuBattleSettlementTem settle = reqMsg.getSettle();
                DouLuoDaLuMgr.addPatronsBattleSettleLog(player, reqMsg.getLog(), settle, false);
            }
        }

        if(reqMsg.hasAllScore()){
            player.getModule(DouLuoDaLuModule.class).updateConditionValue(reqMsg.getAllScore(), eGamePlayerEventType.DouLuoDaLuPhaseTwoUserScoreCrossRank.getValue());
        }

        if(reqMsg.hasScore() && config != null){
            //player.getModule(CurrencyModule.class).addCurrency(config.SCORE_ITEM_ID_FIGHT + "=" + reqMsg.getScore(), eLogMoneyType.DouLuoDaLuActivity, eLogMoneyType.DouLuoDaLuBattlePatronsReward);
        }

        player.sendPacket(Protocol.U_DOU_LUO_DA_LU_PATRONS_BATTLE, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
